﻿using System;
using System.Text;
using log4net;

namespace Alifellod.Logging
{
    /// <summary>
    /// 日志记录器
    /// 当前使用Log4net
    /// </summary>
    public class LoggerDAL
    {
        private static readonly ILog MLogger = LogManager.GetLogger("MainLoger");
        private LoggerDAL()
        {
            //string congfig = GLDS.log4netMSSqlconfig.Replace("{@CNNS}", @"Data Source=.\SQLEXPRESS;Initial Catalog=WWDPS;Integrated Security=True");
            //congfig = congfig.Replace("{@CNNT}", "System.Data.SqlClient.SqlConnection,System.Data,Version=2.0.0.0,Culture=Neutral, PublicKeyToken=b77a5c561934e089");
            //log4net.Config.XmlConfigurator.Configure(new MemoryStream(Encoding.UTF8.GetBytes(congfig)));
        }
        public static ILog Logger
        {
            get
            {
                if (!MLogger.Logger.Repository.Configured)
                {
                    StringBuilder sb = new StringBuilder();
                    foreach (var message in MLogger.Logger.Repository.ConfigurationMessages)
                    {
                        sb.AppendLine(message.ToString());
                    }
                    throw new Exception(sb.ToString());
                }
                return MLogger;
            }
        }

        public static void Debug(object message)
        {
            Logger.Debug(message);
        }

        public static void Debug(object message, Exception exception)
        {
            Logger.Debug(message,exception);
        }

        public static void DebugFormat(string format, params object[] args)
        {
            Logger.DebugFormat(format, args);
        }

        public static void DebugFormat(IFormatProvider provider, string format, params object[] args)
        {
            Logger.DebugFormat(provider, format, args);
        }

        public static void Info(object message)
        {
            Logger.Info(message);
        }

        public static void Info(object message, Exception exception)
        {
            Logger.Info(message,exception);
        }

        public static void InfoFormat(string format, params object[] args)
        {
            Logger.InfoFormat(format, args);
        }

        public static void InfoFormat(IFormatProvider provider, string format, params object[] args)
        {
            Logger.InfoFormat(provider,format, args);
        }

        public static void Warn(object message)
        {
            Logger.Warn(message);
        }

        public static void Warn(object message, Exception exception)
        {
            Logger.Warn(message, exception);
        }

        public static void WarnFormat(string format, params object[] args)
        {
            Logger.WarnFormat(format, args);
        }

        public static void WarnFormat(IFormatProvider provider, string format, params object[] args)
        {
            Logger.WarnFormat(provider, format, args);
        }

        public static void Error(object message)
        {
            Logger.Error(message);
        }

        public static void Error(object message, Exception exception)
        {
            Logger.Error(message, exception);
        }

        public static void ErrorFormat(string format, params object[] args)
        {
            Logger.ErrorFormat(format, args);
        }

        public static void ErrorFormat(IFormatProvider provider, string format, params object[] args)
        {
            Logger.ErrorFormat(provider, format, args);
        }

        public static void Fatal(object message)
        {
            Logger.Fatal(message);
        }

        public static void Fatal(object message, Exception exception)
        {
            Logger.Fatal(message, exception);
        }

        public static void FatalFormat(string format, params object[] args)
        {
            Logger.FatalFormat(format, args);
        }

        public static void FatalFormat(IFormatProvider provider, string format, params object[] args)
        {
            Logger.FatalFormat(provider, format, args);
        }
    }
}
